package com.example.apngdemo;

import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.github.penfeizhou.animation.apng.APNGDrawable;

import java.io.File;
import java.io.IOException;

public class GlideHelper {


    /**
     * 加载图片 默认无占位
     *
     * @param url
     * @param iv
     */
    public static void load2(String url, ImageView iv) {
        Glide.with(iv).load(url).centerCrop().skipMemoryCache(true)
                .diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
    }

    public static void loadAssets(String name, ImageView iv) {
        try {
            Glide.with(iv).load(Drawable.createFromStream(iv.getContext().getAssets().open(name), null)).into(iv);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 加载Apng
     *
     * @param apngDrawable
     * @param iv
     */
    public static void loadApng(APNGDrawable apngDrawable, ImageView iv) {
        Glide.with(iv).load(apngDrawable)
                .diskCacheStrategy(DiskCacheStrategy.NONE).into(iv);
    }
}
